﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Management/Site.Master"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
 <script src="../js/jquery-1.7.1.min.js" type="text/javascript"></script>    
    <script src="../js/jquery.ui.js" type="text/javascript"></script>
    <script src="../js/repeater.js" type="text/javascript"></script>
    <script src="../js/pager.js" type="text/javascript"></script>  
    <link href="../styles/pager.css" rel="stylesheet" type="text/css" />
    <link href="../styles/style.css" rel="stylesheet" type="text/css" />        
    <script src="../js/blockUI.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table id="list">
        <thead>
        <tr><th colspan="6" style="text-align:right;"><a href="Edit.aspx?code=-1" >新增</a></th></tr>
            <tr>
                <th>
                    标题
                </th>
                <th>
                    描述
                </th>
                <th>
                    链接
                </th>
                <th>
                    编辑
                </th>
                <th>
                    排序
                </th>
                <th>
                    删除
                </th>
            </tr>
        </thead>
        <tbody>
            <!--<tr><td>[Title]</td><td>[Content]</td><td>[Remark]</td><td><span class="edit" code="[Code]"><a href="Edit.aspx?code=[Code]">编辑</a></span></td><td><span class="up" code='[Code]'>向上</span>&nbsp;<span class="down" code='[Code]'>向下</span></td><td><span class="delete" code='[Code]'>删除</span></td></tr>-->
        </tbody>
        <tfoot>
            <tr>
                <td colspan="7">
                    <div id="pager" psize='10'>
                    </div>
                </td>
            </tr>
        </tfoot>
    </table>
    <script type="text/javascript">
        $(function () {
            var $list = $("#list>tbody:first");
            //绑定列表方法
            var BindData = function () {
                $.blockUI({ message: "<h2>数据加载中.......</h2>", css: { width: "300px", height: "50px"} });
                $list.template({ autoBind: false });
                $.ajax({ url: "../AjaxHandler/BannersList.ashx?t=" + new Date(),
                    data: {
                        pindex: 1,
                        psize: $("#pager").attr("psize"),
                        action: "List"
                    },
                    type: "post",
                    success: function (data) {
                        pcount = data.Data.Pager.PageCount;
                        $("#pager").pager({ pagenumber: 1, pagecount: pcount, buttonClickCallback: PageClick });
                        $list.template("bindData", data.Data.Rows);
                        $.unblockUI();

                    }
                });
                $list.find("tr", function () {
                    $(this).addClass("altertr");
                });
            }
            BindData();
            //分页标签事件
            var PageClick = function (pageclickednumber) {

                $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pcount, buttonClickCallback: PageClick });
                $.ajax({ url: "../AjaxHandler/BannersList.ashx?t=" + new Date(),
                    data: {
                        pindex: pageclickednumber,
                        psize: $("#pager").attr("psize"),
                        action: "List"
                    },
                    type: "post",
                    success: function (data) {
                        $list.template("bindData", data.Data.Rows);
                    }
                });
            }
            //高亮选中行
            $list.delegate("tr", "mouseover", function () {
                $(this).addClass("altertr");
            });
            //取消高亮选中行
            $list.delegate("tr", "mouseout", function () {
                $(this).removeClass("altertr");
            });
            //排序开始
            $list.delegate("span.up", "click", function () {
                var code = $(this).attr("code");
                Order(true, code); //向上排序
            });

            $list.delegate("span.down", "click", function () {
                var code = $(this).attr("code");
                Order(false, code); //向下排序
            });

            //排序函数
            var Order = function (moveUp, id) {
                $.post("../AjaxHandler/BannersList.ashx?t=" + new Date(), { action: "Order", up: moveUp, code: id }, function (d) {
                    if (d == "1") {
                        BindData();
                    } else {
                        alert("排序失败！");
                    }
                });
            }

            //排序结束

            //删除开始
            $list.delegate("span.delete", "click", function () {
                if (confirm("确定要删除吗？")) {
                    var id = $(this).attr("code");
                    $.post("../AjaxHandler/BannersList.ashx?t=" + new Date(), { action: "Delete", code: id }, function (d) {
                        if (d == "1") {
                            alert("删除成功！");
                            BindData();
                        } else {
                            alert("删除失败！");
                        }
                    });
                }
            });
            //删除结束
        });
    </script>
</asp:Content>
